﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.IO;

namespace TPCN
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            if(!File.Exists(Server.MapPath("~/statics.txt")))
            {
                File.WriteAllText(Server.MapPath("~/statics.txt"),"0");
            }
            Application["visitor"] = Int32.Parse(File.ReadAllText(Server.MapPath("~/statics.txt")));
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            if (Application["online"] == null)
                Application["online"] = 1;
            else
                Application["online"] = (int)Application["online"] + 1;
            Application["visitor"] = (int)Application["visitor"] + 1;
            File.WriteAllText(Server.MapPath("~/statics.txt"), Application["visitor"].ToString());

            HttpContext.Current.Session["cart"] = null;
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {
            Application["online"] = (int)Application["online"] - 1;
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}